package zcj.stu.dao;

import com.mongodb.client.result.DeleteResult;
import com.mongodb.client.result.UpdateResult;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Repository;
import zcj.stu.Entity.Goods;

import javax.annotation.Resource;
import java.util.List;

@Repository
public class GoodsDao {
    @Resource
    private MongoTemplate mongoTemplate;
    public Goods add(Goods goods) {
        return mongoTemplate.insert(goods);
    }

    public UpdateResult edit(Query query, Update update) {
        return mongoTemplate.updateFirst(query,update, Goods.class);
    }

    public DeleteResult del(Query query) {
        return mongoTemplate.remove(query, Goods.class);
    }

    public List<Goods> all(Query query) {
        return mongoTemplate.find(query,Goods.class);
    }
}
